package edu.zut.cs.software.cms.module.teacher.web.spring.controller;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import edu.zut.cs.software.cms.base.web.spring.controller.GenericController;
import edu.zut.cs.software.cms.module.teacher.domain.Teacher;
import edu.zut.cs.software.cms.module.teacher.service.TeacherManager;

/**
 * 
 * @author 15869
 *
 */
@Controller
@RequestMapping("/teacher")
public class TeacherController extends GenericController<Teacher, Long, TeacherManager> {
	TeacherManager teacherManager;

	
	@Autowired
	public void setTeacherManager(TeacherManager teacherManager) {
		this.teacherManager = teacherManager;
		this.manager = this.teacherManager;
	}

	@RequestMapping(method = RequestMethod.GET, value = "/index.html")
	public String index() {
		String result = "/clazz/index";
		return result;
	}

	@RequestMapping("/deleteOneInformation")
	@ResponseBody
	public String deleteOneInformation(long id) {
		if (teacherManager.deleteById(id)) {
			teacherManager.delete(id);
			return "delete success";

		} else
			return "failure";
	}
	
	
	@RequestMapping("/modifyOneTeacher")
	@ResponseBody
	public String modifyOneTeacher(long id,String grade) {
		
		if(teacherManager.modifyById(id, grade)==true)
			return "success!";
		else
			return "failed!";
	}
	
	@RequestMapping("/CreateOne")
	@ResponseBody
	public String CreateOne(String name,String code,String course) {
		String flag="";
		Teacher teacher=new Teacher();
		if(teacherManager.IfExist(name))//返回true
		{
			flag="true";
			teacher.setName(name);
			teacher.setCode(code);
			teacher.setCourse(course);
			teacherManager.save(teacher);
		}
		else {
			flag="false";
		}
		return flag;
	}
}
